/**
 *	\file Hash-tools.h
 *	\brief stores some useful function to compute double hash
 *
 *	TODO documentation
 *
 * 	\date Nov 15, 2013
 * 	\author koldar
 *	\version 1.0
 */
#ifndef HASH_TOOLS_H_
#define HASH_TOOLS_H_

//TODO documentation
typedef void* Pointer;

//TODO documentation
typedef Pointer AbsolutePointer;

//TODO documentation
typedef Pointer RelativePointer;

//FIXME MainHash is basically the domain of the possible values of the hash... maybe it is equal to HashTableValue?
/**Represents a more complex hash than DirectHash. It is mainly used in open address hashtable
 * with a double hash scanner sequence.
 */
typedef unsigned int MainHash;

/**Represents a simple hash computed only form the key, without any additional information
 *
 */
typedef unsigned long DirectHash;

/**@brief converts a string in a hash
 *
 * The function converts a string into an hash. The algorithm used is called "djb2":
 * for further information about this type of hash please consult the page
 * http://www.cse.yorku.ca/~oz/hash.html
 *
 * @param str the stirng to be converted
 * @return the hash of this string
 */
DirectHash hashString(const char* str);

/**@brief compute the hash of a open address hashtable, double hashing iteration mode.
 *
 * Some advice when using this function:
 * \li key should be generate with function like stringToInt();
 * \li iteration is computed inside the algorithm to add/find keys in the hashtable;
 * \li n_1 should be prime;
 * \li n_2 should be a little less of n_1;
 * \li n should be prime and may be equal to n_1;
 *
 * @param key the number of which compute the hash. You can use function like stirngToInt() to compute it
 * @param iteration the current iteration of the open address hashtable
 * @param n_1 the modulo of the first hash
 * @param n_2 the modulo of the second hash
 * @param n the size of the hashtable that will store the key
 * @return the expression \f$ ((k mod n_1)+i(1+ k mod n_2))mod n\f$
 */
MainHash hash(DirectHash key,int iteration,unsigned int n_1,unsigned int n_2,unsigned int n);



#endif /* HASH_TOOLS_H_ */
